package 数学作业.homework3.test1;

import java.util.Random;

public class 冒泡排序 {
    public static void main(String[] args) {
        Random ran = new Random();
        int[] arr = new int[100];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = ran.nextInt(101);
        }
        BubbleSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    public static void swap(int[] arr,int left,int right){
        int tmp = arr[left];
        arr[left] = arr[right];
        arr[right] = tmp;
    }

    public static void BubbleSort(int[] arr){
        for(int i = arr.length;i > 0;i--){
            for(int j = 1;j < i;j++){
                if(arr[j] < arr[j - 1]){
                    swap(arr,j,j - 1);
                }
            }
        }
    }
}
